package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.*;
import com.heima.wemedia.service.IWmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private IWmNewsService wmNewsService;
    /**
     * 内容列表查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageDto dto){
        ResponseResult responseResult = wmNewsService.findAll(dto);
        return responseResult;
    }

    /**
     * 文章发布和保存草稿
     * status  0  保存草稿
     * status  1  发布文章
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto){
        return wmNewsService.submitNews(dto);
    }

    /**
     * 查询单个文章
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult findById(@PathVariable Integer id){
        return wmNewsService.findById(id);
    }

    /**
     * 删除文章
     * @param id 根据id删除
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        return wmNewsService.deleteById(id);
    }

    /**
     * 根据id修改文章上下架状态
     * @param dto
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult DownOrUp(@RequestBody WmNewsDownOrUpDto dto){
        return wmNewsService.DownOrUp(dto);
    }

    /**
     * 后台管理端查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult listVo(@RequestBody WmNewsAuthDto dto){
        return wmNewsService.listVo(dto);
    }

    /**
     * 后台管理查询文章详情
     * @return
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult oneVo(@PathVariable Integer id){
        return wmNewsService.oneVo(id);
    }

    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody WmNewsAuthPassOrFailDto dto){
        return wmNewsService.authPass(dto);
    }

    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody WmNewsAuthPassOrFailDto dto){
        return wmNewsService.authFail(dto);
    }
}
